package com.zc.baseclass.mysql.test;

import java.util.List;
import java.util.Map;
import java.util.Set;

import com.zc.baseclass.mysql.main.MysqlBase;

public class testMysqlBase {

	public static void main(String[] args) {
		//testSelect();
		//testSelectList();
		//testSelectMap();
		//testCreateAndDrop();
		testDemo();
	}
	
	private static void testDemo() {
		MysqlBase mb = new MysqlBase();
		mb.connectMysql( "root", "0515", "mysqltest");
		
		String result = mb.processTableData(mb.select("employee", "select * from employee"));
		System.out.println(result);
		
		mb.disconnectMysql();
	}

	private static void testCreateAndDrop() {
		MysqlBase mb = new MysqlBase();
		mb.connectMysql( "root", "0515", "mysqltest");
		
		mb.createDatabase("hello", "create database hello");
		mb.createTable("test", "create table test(id int, name varchar(80))");
		
		mb.dropTable("test", "drop table test");
		mb.dropDatabase("hello", "drop database hello");
		
		mb.disconnectMysql();
	}
	
	private static void testSelect() {
		MysqlBase mb = new MysqlBase();
		mb.connectMysql( "root", "0515", "mysqltest");
		mb.select("employee","select * from employee");
		mb.disconnectMysql();
	}
	
	private static void testSelectList() {
		MysqlBase mb = new MysqlBase();
		mb.connectMysql( "root", "0515", "mysqltest");
		List<List<Object>> list = mb.selectList("employee","select * from employee");
		for(List<Object> list2 : list) {
			for(Object obj : list2) {
				System.out.print(obj + " ");
			}
			System.out.println();
		}
		/*
		for(int i=0; i<list.size(); i++) {
			List<Object> list2 = list.get(i);
			for(int j=0; j<list2.size();j++) {
				System.out.print(list2.get(j) + " ");
			}
			System.out.println();
		}
		*/
		
		mb.disconnectMysql();
	}
	
	private static void testSelectMap() {
		MysqlBase mb = new MysqlBase();
		mb.connectMysql( "root", "0515", "mysqltest");
		List<Map<String,Object>> list = mb.selectMap("employee","select * from employee");
		for(Map<String,Object> map : list) {
			for(String str : map.keySet()) {
				System.out.print(str+":"+map.get(str) + " ");
			}
			System.out.println();
		}
		/*
		for(int i=0; i<list.size(); i++) {
			Map<String,Object> map = list.get(i);
			for(String str : map.keySet()) {
				System.out.print(str+":"+map.get(str) + " ");
			}
			System.out.println();
		}
		*/
		
		mb.disconnectMysql();
	}

}
